<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Cache a variable in the data store</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.apc-store" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">apc_store</h1>
  <p class="verinfo">(PECL apc &gt;= 3.0.0)</p><p class="refpurpose"><span class="refname">apc_store</span> &mdash; <span class="dc-title">
   Cache a variable in the data store
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.apc-store-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>apc_store</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>
  ] ) : <span class="type">bool</span></div>

  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>apc_store</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$unused</code><span class="initializer"> = NULL</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>
  ]] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   缓存一个变量到APC中
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    与PHP中其他的机制不同，使用<span class="function"><strong>apc_store()</strong></span> 存储的变量
    在不同的请求之间一直持久存在（直到从缓存系统中移除）。
   </span>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.apc-store-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">key</code></dt>

     <dd>

      <p class="para">
       存储缓存变量使用的名称.<code class="parameter">key</code>是唯一的，所以
       两个值使用同一个 <code class="parameter">key</code>，原来的将被新的值覆盖。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">var</code></dt>

     <dd>

      <p class="para">
       The variable to store
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">ttl</code></dt>

     <dd>

      <p class="para">
       生存时间;在缓存中存储<code class="parameter">var</code>共<code class="parameter">ttl</code>秒,
       在<code class="parameter">ttl</code>秒过去后,存储的变量将会从缓存中擦除(在下一次请求时),
       如果没有设置<code class="parameter">ttl</code>(或者<code class="parameter">ttl</code>是<em>0</em>),
       变量将一直存活到被手动移除为止,除此之外不在缓存中的可能原因是，
       缓存系统使用clear，或者restart等。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">values</code></dt>

     <dd>

      <p class="para">
       Names in key, variables in value.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.apc-store-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
   Second syntax returns array with error keys.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.apc-store-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-411">
    <p><strong>Example #1 <span class="function"><strong>apc_store()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'BAR'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">apc_store</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">apc_fetch</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(3) &quot;BAR&quot;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.apc-store-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="apc_add.html" class="function" rel="rdfs-seeAlso">apc_add()</a> - 缓存一个变量到数据存储</span></li>
    <li class="member"><span class="function"><a href="apc_fetch.html" class="function" rel="rdfs-seeAlso">apc_fetch()</a> - 从缓存中取出存储的变量</span></li>
    <li class="member"><span class="function"><a href="apc_delete.html" class="function" rel="rdfs-seeAlso">apc_delete()</a> - 从用户缓存中删除某个变量</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>